// 模块化快捷键 vuex-modules
import axios from "axios"
const moduleName = {
    namespaced: true,
    state: {
        table_data:[],
        copy_data: [],
    },
    mutations: {
        set_tabledata(state,payload) {
            state.table_data = payload
            state.copy_data = payload
        },
        del_tabledata(state,payload) {
            console.log(payload);
            state.table_data = state.copy_data.forEach((item,index) => {
                if (item.id === payload.id) {
                    state.copy_data.splice(index,1);
                }
            });
        },
        edit_table_data(state,payload) {
            state.table_data.forEach((item,index) => {
                if (item.id === payload.id) {
                    state.table_data[index] = {...payload}
                }
            })
        }
    },
    actions: {
        get_list: async({commit}) => {
            let {data} = await axios.get("/api/table")
            commit("set_tabledata",data)
        }
    },
}
export default moduleName